<?php

require_once '../../includes/classes/core.php';
require_once '../../includes/classes/wsdl.class.php';

$user=$_SESSION['USERID'];

$res = mysql_fetch_assoc(mysql_query("SELECT crystal_users.username
		FROM 	 crystal_users
		WHERE  crystal_users.id=$user"));
$user_name=$res[username];

$wsdl   = new wsdl('http://192.168.215.30/services/public/callcentersupportservice.asmx?wsdl', 'CallCenter', '2cc4541a13009ba5da9b90a146d10369', '192.168.200.145', $user_name, 'index.php');
$data   = '';

$action = $_REQUEST['act'];

switch ($action) {
    
    case 'pin':
        
        $pin    = $_REQUEST['pin'];
        $pid    = $_REQUEST['pid'];
        
        $tt     = $wsdl->SearchClient($pin, $pid);
        $page   = $wsdl->GenerateRedirect($tt);
        
        if ($tt) {
            $data = array('page' => $page);
        }else {
            $data = array('page' => 'error');
        }
        
    break;
    
    case 'phone':
        
        $phone  = $_REQUEST['phone'];
        
        $result = $wsdl->SearchClientByPhone($phone);
        
        if ($result[0]) {
            
            $page   = $wsdl->GenerateRedirect($result[1]);
            $data   = array('page' => $page, 'status' => 'true');
            
        }else {
            
            $data   = array('status' => 'false');
            
        }
        
    break;
    
    case 'check_group':
    
        $result = $wsdl->GetRolesList();
        
        for ($i = 0; $i < count($result); $i++) {
            
            $RoleId = $result[$i][RoleId];
            $RoleName = $result[$i][RoleName];
                
            mysql_query("INSERT INTO `group` (`id`, `name`)
                        VALUES ($RoleId, '$RoleName')
                        
                        ON DUPLICATE KEY UPDATE name='$RoleName'");
            
            $data   = array('status' => 'true');
        }
        
    break;
    
    default:
        ;
    break;
    
}

echo json_encode($data);